** Data reading and variable selection from raw data
** UK National Survey of Sexual Attitudes and Lifestyle 1990


** 01. Reading data **

cap log close
clear all
cd /*insert you work directory here*/
use /*read your data here*/
set more off
numlabel, add


** 02. Consructing year and country variables **

ge year=1990
lab var year "survey year"

ge country=826
lab var country "ISO country code"
//uk: 826 


** 03. ID variables **

ge pid=sn  /* individual serial number */
lab var pid "person id"


** 04. Basic Demographics (Sex and Age/birth year) **

ge sex=q1b
lab var sex "sex"
lab def sex 1 "male" 2 "female"
lab val sex sex

ge age=q1a
lab var age "age"  

ge birthyr=.
replace birthyr=1990-age 
lab var birthyr "year of birth"


** 05. Siblings **

ge nsibs=q7b  /* inc step-siblings, exc R */
recode nsibs (98/99=.)  /* recode 98 & 99 to missing */
lab var nsibs "number of siblings"

* number of step-siblings available
ge nstepsibs=q7e  /* inc step-siblings, exc R */
recode nstepsibs (98/99=.)  /* recode 98 & 99 to missing */
lab var nstepsibs "number of step-siblings"

* birth order: only rough position is available
ge birthorder=q7c
recode birthorder (1 4=1) (3=2) (2=3) (9=.)
lab var birthorder "birth order (3 cats)"
lab def birthorder 1 "oldest" 2 "in between" 3 "youngest"
lab val birthorder birthorder


** 06. Own education: educ **

tab educ, m


** 07. Parents' education: Father and/or Mother **

// no measures for parental status (education, class, occupations...)


** 08. Own occupation **

rename seg class


** 10. Tabulate the Identified Variables **

numlabel, add
log using /*insert you work directory here*/, replace text


** Data reading and variable selection from raw data
** UK National Survey of Sexual Attitudes and Lifestyle 1990


** Sex **
tab sex,m

** Age, Birth Year **
sum age birthyr, d

** Siblings **
sum nsibs birthorder, d


** R's Own Education & Occupation **
tab1 educ class,m

log close


** 11. Keep the identified variables only

keep year country pid  ///
	 sex age birthyr ///
	 nsibs nstepsibs birthorder ///
	 class educ

** 12. Save the Data File **

saveold /*insert you work directory here*/, replace
